<template>
	<div>
		<el-card class="!border-none" shadow="never">
			<el-alert type="warning" title="挖矿产出 = 挖矿速度(根据会员等级) x 工作周期"
				:closable="false" show-icon />
		</el-card>
		<el-card shadow="never" class="!border-none">
			<el-form ref="formRef" class="ls-form" label-position="top">
				<el-form-item label="挖矿货币" prop="name">
					<div class="w-80">
						<el-input v-model.trim="mineData.name" placeholder="请输入挖矿货币"></el-input>
					</div>
				</el-form-item>
				<el-form-item label="货币符号" prop="symbol">
					<div class="w-80">
						<el-input v-model.trim="mineData.symbol" placeholder="请输入货币符号"></el-input>
					</div>
				</el-form-item>
				<el-form-item label="货币汇率" prop="rate">
					<div class="w-80">
						<el-input v-model.trim="mineData.rate" type="number" placeholder="请输入货币汇率"></el-input>
					</div>
				</el-form-item>
				<el-form-item label="汇率标识" prop="symbol_rate">
					<div class="w-80">
						<el-input v-model.trim="mineData.symbol_rate" placeholder="请输入汇率标识"></el-input>
						<div class="form-tips">用于自动更新汇率，汇率为1或无需更新可不填</div>
					</div>
				</el-form-item>
				<el-form-item label="显示精度" prop="precision">
					<div class="w-80">
						<el-input v-model.trim="mineData.precision" type="number" placeholder="请输入显示精度"></el-input>
					</div>
				</el-form-item>
				<el-form-item label="工作周期" prop="cycle">
					<div class="w-80">
						<el-input v-model.trim="mineData.cycle" type="number" placeholder="请输入工作周期"></el-input>
						<div class="form-tips">用户多长时间可以领取一次挖矿奖励，单位：小时</div>
					</div>
				</el-form-item>
				<el-form-item label="有效天数" prop="valid_days">
					<div class="w-80">
						<el-input v-model.trim="mineData.valid_days" type="number" placeholder="请输入有效天数"></el-input>
						<div class="form-tips">超过天数未领取，奖励自动清空，需重启矿机才可继续挖矿</div>
					</div>
				</el-form-item>
				<el-form-item label="自动挖矿" prop="is_auto">
					<div>
						<el-switch v-model="mineData.is_auto" :active-value="'1'" :inactive-value="'0'" />
						<div class="form-tips">关闭后，用户需手动启动矿机</div>
					</div>
					
				</el-form-item>
			</el-form>
		</el-card>

		<footer-btns v-perms="['setting.web.web_setting/setWebsite']">
			<el-button type="primary" @click="handleSubmit">保存</el-button>
		</footer-btns>
	</div>
</template>

<script lang="ts" setup name="dictType">
	import { isEmpty } from 'lodash-es';
	import { getWebsiteProject, setWebsiteProject } from '@/api/setting/website'

	const name = ref('mine')

	// 表单数据
	const mineData = reactive({
		name: "",
		rate: "",
		symbol_rate:'',
		symbol: "",
		precision: "",
		cycle:'',
		valid_days:'',
		is_auto:'1'
	})
	const handleSubmit = async () => {
		await setWebsiteProject({ name: name.value, content: mineData })
		getData()
	}

	const getData = async () => {
		const data = await getWebsiteProject({ name: name.value })
		if (!isEmpty(data.data)) {
			for (const key in mineData) {
				if (data.data[key] != null && data.data[key] != undefined) {
					//@ts-ignore
					mineData[key] = data.data[key]
				}
			}
		}
	}

	getData()
</script>

<style lang="scss" scoped></style>